<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h1>我的微博列表</h1>
<div>
    <div v-for="weibo in arr">
        <h3>{{weibo.content}}</h3>
        <p>发布于:{{weibo.created}}<a href="javascript:void (0)" @click="del(weibo.id)">删除</a></p>
    </div>
</div>

<!--引入vue和axios-->
<script src="https://lf3-cdn-tos.bytecdntp.com/cdn/expire-1-M/vue/2.6.14/vue.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<script src="http://cdn.staticfile.org/moment.js/2.24.0/moment.min.js"></script>

<script>
    let v = new Vue({
        el:"body>div",
        data:{
            arr:[]
        },
        created:function () {
            //发请求获得当前登录用户发布的所有微博
            axios.get("weibo/selectMyself").then(function (response) {
                v.arr = response.data;
                for (let weibo of v.arr) {
                    //修改时间格式
                    weibo.created=moment(weibo.created).format("YYYY年MM月DD日 HH:mm:ss");
                }
            })
        },
        methods:{
            del:function (id) {
                if (confirm("确认删除么")){
                    axios.get("weibo/delete?id="+id).then(function () {
                        alert("删除成功");
                        location.reload();
                    })
                }
            }
        }

    })
</script>
</body>
</html>